package com.cisetech.web.bobocai.houtai;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cisetech.service.SinglePageService;
import com.cisetech.vo.bobocai.SinglePageVo;


//单页管理控制器
@Controller
@RequestMapping(value="/ht/singlePage")
public class SinglePageController {
	Logger log = LoggerFactory.getLogger(SinglePageController.class);
	@Autowired
	private SinglePageService singlePageService;
	
	@RequestMapping(value="{id}")
	public ModelAndView getPage(@PathVariable("id") String id,HttpServletRequest request,HttpServletResponse response){
		ModelAndView v = new ModelAndView("/houtai/singlePage");
		SinglePageVo singlePageVos = singlePageService.findSinglePageVoById(Integer.parseInt(id));
		if(singlePageVos == null){
			singlePageVos = new SinglePageVo();
		}
		singlePageVos.setResouceId(Integer.parseInt(id));
		v.addObject("singlePageVo", singlePageVos);
		log.info("id======="+id);
		return v;
	}
	@ResponseBody
	@RequestMapping(value="save/{id}")
	public String savePage(@PathVariable("id")String id,SinglePageVo singlePageVo,HttpServletRequest request,HttpServletResponse response){
		int i=0;
		if(!"".equals(id) && id!=null){
			singlePageVo.setResouceId(Integer.parseInt(id));
			SinglePageVo singlePageVos = singlePageService.findSinglePageVoById(Integer.parseInt(id));
			if(singlePageVos!=null){
				i = singlePageService.updatePage(singlePageVo);
			}else{
				i = singlePageService.savePage(singlePageVo);
			}
		}
		return i+"";
	}
}
